package com.food.restaurantpro.connection;

import com.food.restaurantpro.R;
import com.food.restaurantpro.RestaurantApp;

import android.content.res.Resources;

public enum ErrorCode {
	TIME_OUT("0001"), SERVER_ERROR("0002"), NETWORK_ERROR("0003");

	private String mErrorCode;

	ErrorCode(String errorCode) {
		mErrorCode = errorCode;
	}

	public static ErrorCode getErrorCode(String errorCode) {
		ErrorCode code = null;
		if (errorCode.equals("0001")) {
			code = ErrorCode.TIME_OUT;
		} else if (errorCode.equals("0002")) {
			code = ErrorCode.SERVER_ERROR;
		} else if (errorCode.equals("0003")) {
			code = ErrorCode.NETWORK_ERROR;
		} else {
			code = ErrorCode.SERVER_ERROR;
		}
		return code;
	}

	public String getErrorMessage() {
		Resources res = RestaurantApp.CURRENT_CONTEXT.getResources();
		String mes = "";
		if (mErrorCode.equals("0001")) {
			mes = res.getString(R.string.TIME_OUT);
		} else if (mErrorCode.equals("0002")) {
			mes = res.getString(R.string.SERVER_ERROR);
		} else if (mErrorCode.equals("0003")) {
			mes = res.getString(R.string.NETWORK_ERROR);
		} else {
			mes = res.getString(R.string.SERVER_ERROR);
		}
		return mes;
	}
}
